home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9019 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with sin() - big problem
  5. Date: 7 Mar 1996 18:14:42 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4hnql2$3ks@umbc9.umbc.edu>
  8. References: <4hhusi$49i@sunburst.ccs.yorku.ca>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Naftali Sturm <yu114405@yorku.ca> wrote:
  13. |> I have a big problem.
  14. |> I am making a math and trigonometry program which, one of its functions
  15. |> is to compute the sine of a number.
  16. |>  The way I did it was. 
  17. |>     result = sin(numb);
  18. |> 
  19. |> result and num are both float's.
  20. |>  The problem is that when numb is 1.0, the
  21. |> program gives me .84147 , and when numb is 45.0 
  22. |> the program gives me .85090, and each number is a different result.
  23. |> However I took a look at my sine table in my trigonometry book, and
  24. |> it says the sine of 1 is .018, the sine of 45 is .707, and
  25. |> different results than what my program said.
  26. |>   Why?
  27. |> 
  28. |> thank(you); for(your=help;;) { }
  29.  
  30. Well the <math.h> library sin() function uses radians instead of degrees.
  31. A radian is the length of the radius of a particular circle and in
  32. Euclidean geometry all circles have exactly 2*pi of these. So a 45 degree
  33. angle would be pi/4 radians. Using the simple fact that there is 360
  34. degrees in a circle you can multiply all your degree measures by
  35. pi/180 before passing them to sin() and everything will work fine.
  36. Just make sure everything is floating point in your actual code ;-).
  37. -- 
  38. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  39.  
  40. Jonas J. Schlein  (schlein@gl.umbc.edu)
  41.